package jjn.daily;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023/8/26 23:52
 */
public class LeetCode228 {
    public List<String> summaryRanges(int[] nums) {
        List<String> result = new ArrayList<>();
        for (int i = 0; i < nums.length; i++) {
            StringBuilder stringBuilder = new StringBuilder();
            int left = i, right = i + 1;
            while (left < nums.length && right < nums.length && nums[right] - nums[left] == 1) {
                left++;
                right++;
            }
            int rightIndex = Math.min(left, nums.length - 1);
            if (rightIndex == i) {
                stringBuilder.append(nums[i]);
            } else {
                stringBuilder.append(nums[i]);
                stringBuilder.append("->");
                stringBuilder.append(nums[rightIndex]);
            }
            result.add(stringBuilder.toString());
            i = left;
        }
        return result;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int total = scanner.nextInt();
        int[] nums = new int[total];
        for (int i = 0; i < total; i++) {
            nums[i] = scanner.nextInt();
        }
        List<String> list = new LeetCode228().summaryRanges(nums);
        System.out.println(list);
    }
}
